class Solution {
public:
    int min(int a, int b)
    {
        return a <= b ? a : b;
    }
    string longestCommonPrefix(vector<string>& strs) {
        int mi = 1e9;
        if (!strs.size())return "";
        if (strs.size() == 1)return strs[0];
        for (int i = 0; i < strs.size(); i++) {
            mi = min(mi, strs[i].size());
        }
        string ans;
        string temp = strs[0];
        for (int i = 0; i < mi; i++) {
            bool f = 0;
            for (int j = 1; j < strs.size(); j++) {
                if (strs[j][i] != strs[j - 1][i]) {
                    f = 1;
                    break;
                }
            }
            if (f)break;
            ans += strs[0][i];
        }
        return ans;
    }
};